package com.zenchn.dynamic;

import static com.zenchn.dynamic.TMiCustomerVisitDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.zenchn.model.TMiCustomerVisit;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface TMiCustomerVisitDynamicMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    BasicColumn[] selectList = BasicColumn.columnList(visitId, contactsId, customerId, visitDate, content, chance, askForHelp, creator, createTime);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<TMiCustomerVisit> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<TMiCustomerVisit> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("TMiCustomerVisitResult")
    Optional<TMiCustomerVisit> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="TMiCustomerVisitResult", value = {
        @Result(column="visit_id", property="visitId", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="contacts_id", property="contactsId", jdbcType=JdbcType.CHAR),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.CHAR),
        @Result(column="visit_date", property="visitDate", jdbcType=JdbcType.DATE),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="chance", property="chance", jdbcType=JdbcType.VARCHAR),
        @Result(column="ask_for_help", property="askForHelp", jdbcType=JdbcType.VARCHAR),
        @Result(column="creator", property="creator", jdbcType=JdbcType.CHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<TMiCustomerVisit> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, TMiCustomerVisit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, TMiCustomerVisit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int deleteByPrimaryKey(String visitId_) {
        return delete(c -> 
            c.where(visitId, isEqualTo(visitId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int insert(TMiCustomerVisit record) {
        return MyBatis3Utils.insert(this::insert, record, TMiCustomerVisit, c ->
            c.map(visitId).toProperty("visitId")
            .map(contactsId).toProperty("contactsId")
            .map(customerId).toProperty("customerId")
            .map(visitDate).toProperty("visitDate")
            .map(content).toProperty("content")
            .map(chance).toProperty("chance")
            .map(askForHelp).toProperty("askForHelp")
            .map(creator).toProperty("creator")
            .map(createTime).toProperty("createTime")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int insertMultiple(Collection<TMiCustomerVisit> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, TMiCustomerVisit, c ->
            c.map(visitId).toProperty("visitId")
            .map(contactsId).toProperty("contactsId")
            .map(customerId).toProperty("customerId")
            .map(visitDate).toProperty("visitDate")
            .map(content).toProperty("content")
            .map(chance).toProperty("chance")
            .map(askForHelp).toProperty("askForHelp")
            .map(creator).toProperty("creator")
            .map(createTime).toProperty("createTime")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int insertSelective(TMiCustomerVisit record) {
        return MyBatis3Utils.insert(this::insert, record, TMiCustomerVisit, c ->
            c.map(visitId).toPropertyWhenPresent("visitId", record::getVisitId)
            .map(contactsId).toPropertyWhenPresent("contactsId", record::getContactsId)
            .map(customerId).toPropertyWhenPresent("customerId", record::getCustomerId)
            .map(visitDate).toPropertyWhenPresent("visitDate", record::getVisitDate)
            .map(content).toPropertyWhenPresent("content", record::getContent)
            .map(chance).toPropertyWhenPresent("chance", record::getChance)
            .map(askForHelp).toPropertyWhenPresent("askForHelp", record::getAskForHelp)
            .map(creator).toPropertyWhenPresent("creator", record::getCreator)
            .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default Optional<TMiCustomerVisit> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, TMiCustomerVisit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default List<TMiCustomerVisit> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, TMiCustomerVisit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default List<TMiCustomerVisit> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, TMiCustomerVisit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default Optional<TMiCustomerVisit> selectByPrimaryKey(String visitId_) {
        return selectOne(c ->
            c.where(visitId, isEqualTo(visitId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, TMiCustomerVisit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    static UpdateDSL<UpdateModel> updateAllColumns(TMiCustomerVisit record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(visitId).equalTo(record::getVisitId)
                .set(contactsId).equalTo(record::getContactsId)
                .set(customerId).equalTo(record::getCustomerId)
                .set(visitDate).equalTo(record::getVisitDate)
                .set(content).equalTo(record::getContent)
                .set(chance).equalTo(record::getChance)
                .set(askForHelp).equalTo(record::getAskForHelp)
                .set(creator).equalTo(record::getCreator)
                .set(createTime).equalTo(record::getCreateTime);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(TMiCustomerVisit record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(visitId).equalToWhenPresent(record::getVisitId)
                .set(contactsId).equalToWhenPresent(record::getContactsId)
                .set(customerId).equalToWhenPresent(record::getCustomerId)
                .set(visitDate).equalToWhenPresent(record::getVisitDate)
                .set(content).equalToWhenPresent(record::getContent)
                .set(chance).equalToWhenPresent(record::getChance)
                .set(askForHelp).equalToWhenPresent(record::getAskForHelp)
                .set(creator).equalToWhenPresent(record::getCreator)
                .set(createTime).equalToWhenPresent(record::getCreateTime);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int updateByPrimaryKey(TMiCustomerVisit record) {
        return update(c ->
            c.set(contactsId).equalTo(record::getContactsId)
            .set(customerId).equalTo(record::getCustomerId)
            .set(visitDate).equalTo(record::getVisitDate)
            .set(content).equalTo(record::getContent)
            .set(chance).equalTo(record::getChance)
            .set(askForHelp).equalTo(record::getAskForHelp)
            .set(creator).equalTo(record::getCreator)
            .set(createTime).equalTo(record::getCreateTime)
            .where(visitId, isEqualTo(record::getVisitId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_visit")
    default int updateByPrimaryKeySelective(TMiCustomerVisit record) {
        return update(c ->
            c.set(contactsId).equalToWhenPresent(record::getContactsId)
            .set(customerId).equalToWhenPresent(record::getCustomerId)
            .set(visitDate).equalToWhenPresent(record::getVisitDate)
            .set(content).equalToWhenPresent(record::getContent)
            .set(chance).equalToWhenPresent(record::getChance)
            .set(askForHelp).equalToWhenPresent(record::getAskForHelp)
            .set(creator).equalToWhenPresent(record::getCreator)
            .set(createTime).equalToWhenPresent(record::getCreateTime)
            .where(visitId, isEqualTo(record::getVisitId))
        );
    }
}